﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using Service.Model.Map;

namespace Service.Model.Context
{
    public class ServiceDbContext : DbContext
    {
        public IDbSet<Game> Games { get; set; }
        public IDbSet<GamePlayer> GamePlayers { get; set; }
        public IDbSet<Player> Players { get; set; }
        public IDbSet<PlayerHeuristic> PlayerHeuristics { get; set; }
        public IDbSet<Heuristic> Heuristics { get; set; }

        public IDbSet<LearningWeight> LearningWeights { get; set; }

        public IDbSet<Opening> Openings { get; set; }


        public ServiceDbContext() : base("name=AIDatabase")
        {
            Database.SetInitializer<ServiceDbContext>(null);
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            modelBuilder.Configurations.Add(new GameMap());
            modelBuilder.Configurations.Add(new GamePlayerMap());
            modelBuilder.Configurations.Add(new PlayerMap());
            modelBuilder.Configurations.Add(new PlayerHeuristicMap());
            modelBuilder.Configurations.Add(new HeuristicMap());

            modelBuilder.Configurations.Add(new OpeningMap());
            modelBuilder.Configurations.Add(new LearningWeightMap());
        }
    }
}